Repository navigation
perf(studio): keep the session between navigations; show pending after 150 ms - #67
Merged
Merged
Conversation
…r 150 ms Every protected route awaited `authClient.getSession()` in `beforeLoad`, a 240-640 ms server round trip before the next screen could start, and the router's default `pendingMs` of 1 s kept the old screen up meanwhile: the URL changed, the screen did not. - lib/session-cache.ts keeps a successful session for 5 minutes and shares a request in flight; it is forgotten on any auth call but get-session (sign-in, sign-out, revoking sessions, a new password) and on any 401 from the API client. - `defaultPendingMs: 150`, `defaultPendingMinMs: 300`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Madraka <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes 1 and 2 of the internal performance review (Studio navigation).
Before: every protected route's
beforeLoadawaitedauthClient.getSession()(240–640 ms measured on studio.cloudhal.com, before the next screen's chunk even started; twice in a row on a cold load), and TanStack Router's defaultpendingMs(1 s) kept the old screen up meanwhile. The URL changed at once and the screen did not.Now:
lib/session-cache.ts: a successful session is kept for 5 minutes and a request in flight is shared. Empty or failed answers are never kept. It is forgotten on any Better Auth call other thanget-session(sign-in, sign-out, revoking sessions, password change, through the client'sonResponsehook) and on any 401 fromlib/api/http.ts, so an expired session still lands on the login at the next navigation.defaultPendingMs: 150,defaultPendingMinMs: 300: a wait shows the pending screen instead of a frozen one.isPlayground().Tests:
session-cache.test.ts; Studio suite 1136/1136.🤖 Generated with Claude Code